<template>
<!--  <h2>档案上下架</h2>-->
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24" ref="hMain">
        <div class="head-container" style="overflow-y: scroll;" :style="{height:tableHeight+'px'}">
          <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                   :filter-node-method="filterNode" :default-expanded-keys="expandedkeys"
                   :current-node-key="currentNodekey" ref="tree" node-key="id" default-expand-all highlight-current
                   @node-click="handleNodeClick">
            <template slot-scope="{ node, data }">
              <span class="span-ellipsis" :title="node.label" :style="size">{{ node.label }}</span>
            </template>
          </el-tree>
        </div>
      </el-col>
      <el-col :span="20" :xs="24">
        <el-tabs v-if="isfondsCode" type="border-card" v-model="activeName" :style="{ height: tableHeight + 'px' }">
          <el-tab-pane label="无数据" name="first">
            <el-empty description=" " style="margin-top:10%;"></el-empty>
          </el-tab-pane>
        </el-tabs>
        <el-tabs v-else v-model="activeName" type="border-card">
          <!-- start 按卷上架 -->
          <el-tab-pane label="按卷上架" name="first">
            <el-form :model="juanParams" ref="juanForm"  :inline="true" v-show="showJuanSearch"
                     label-width="68px">
              <el-form-item label="案卷号" prop="keyword">
                <el-input v-model="juanParams.keyword" placeholder="请输入案卷号" clearable style="width: 240px"
                          @keyup.enter.native="handleJuanQuery" maxlength="30" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search"  @click="handleJuanQuery">查询</el-button>
                <el-button icon="el-icon-refresh"  @click="resetJuanQuery">重置</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-top"  @click="upJuan" v-hasPermi="['archive:warehouseManagement:upDownShelves:upShelves']">上架</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-bottom"  @click="downJuan" v-hasPermi="['archive:warehouseManagement:upDownShelves:downShelves']">下架</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button plain icon="el-icon-document-copy"  @click="adjustJuan" v-hasPermi="['archive:warehouseManagement:upDownShelves:update']">调整档案位置</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(3)">数字化</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(4)">缩微</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(5)">修复</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(6)">保护技术处理</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showJuanSearch"></right-toolbar>
            </el-row>
            <el-table v-loading="juanLoading" :data="juanList" @selection-change="juanSelectionChange" @row-dblclick="openJuanDetails" height="500">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" :index="table_index_juan" prop="id" />
              <el-table-column label="案卷题名" prop="title" :show-overflow-tooltip="true" />
              <el-table-column label="案卷号" prop="ajh" :show-overflow-tooltip="true" />
              <el-table-column label="档号" prop="dh" :show-overflow-tooltip="true" />
              <el-table-column label="保管期限" prop="bgqx" :show-overflow-tooltip="true" />
              <el-table-column label="归档司局" prop="gdsj" :show-overflow-tooltip="true" />
              <el-table-column label="归档处室" prop="gdcs" :show-overflow-tooltip="true" />
              <el-table-column label="上架时间" prop="sjTime" :show-overflow-tooltip="true" />
              <el-table-column label="位置" prop="position" :show-overflow-tooltip="true" />
            </el-table>
            <pagination v-show="juanTotal > 0" :total="juanTotal" :page.sync="juanParams.pageNum"
                        :limit.sync="juanParams.pageSize" @pagination="getJuanList" />
          </el-tab-pane>
          <!-- end 按卷上架 -->

          <!-- start 按盒上架 -->
          <el-tab-pane label="按盒上架" name="second">
            <el-form :model="heParams" ref="heForm"  :inline="true" v-show="showHeSearch"
                     label-width="68px">
              <el-form-item label="盒号" prop="keyword">
                <el-input v-model="heParams.keyword" placeholder="请输入盒号" clearable style="width: 240px"
                          @keyup.enter.native="handleHeQuery" maxlength="30" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search"  @click="handleHeQuery">查询</el-button>
                <el-button icon="el-icon-refresh"  @click="resetHeQuery">重置</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-printer"  @click="printHe" v-hasPermi="['archive:warehouseManagement:upDownShelves:print']">打印盒脊</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-top"  @click="upHe" v-hasPermi="['archive:warehouseManagement:upDownShelves:upShelves']">上架</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-bottom"  @click="downHe" v-hasPermi="['archive:warehouseManagement:upDownShelves:downShelves']">下架</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button plain icon="el-icon-document-copy"  @click="adjustHe" v-hasPermi="['archive:warehouseManagement:upDownShelves:update']">调整档案位置</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(3)">数字化</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(4)">缩微</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(5)">修复</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="modifyState(6)">保护技术处理</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showHeSearch"></right-toolbar>
            </el-row>
            <el-table v-loading="heLoading" :data="heList" @selection-change="heSelectionChange" @row-dblclick="openHeDetails" height="500">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" :index="table_index_he" prop="id" />
              <el-table-column label="盒号" prop="hehao" :show-overflow-tooltip="true" />
              <el-table-column label="档案门类" prop="daml" :show-overflow-tooltip="true" />
<!--              <el-table-column label="整理方式" prop="zlfs" :show-overflow-tooltip="true" />-->
              <el-table-column label="保管期限" prop="bgqx" :show-overflow-tooltip="true" />
              <el-table-column label="起始年度" prop="boxStnd" :show-overflow-tooltip="true" />
              <el-table-column label="终止年度" prop="boxEdnd" :show-overflow-tooltip="true" />
              <el-table-column label="件号(起)" prop="boxStnum" :show-overflow-tooltip="true" />
              <el-table-column label="件号(止)" prop="boxEdnum" :show-overflow-tooltip="true" />
              <el-table-column label="规格" prop="specName" :show-overflow-tooltip="true" />
              <el-table-column label="上架时间" prop="sjTime" :show-overflow-tooltip="true" />
              <el-table-column label="位置" prop="position" :show-overflow-tooltip="true" />
            </el-table>
            <pagination v-show="heTotal > 0" :total="heTotal" :page.sync="heParams.pageNum"
                        :limit.sync="heParams.pageSize" @pagination="getHeList" />
          </el-tab-pane>
          <!-- end 按盒上架 -->
        </el-tabs>
      </el-col>
    </el-row>

    <!-- 打印盒脊 -->
    <printBoxRidge :printBoxOpen="printBoxOpen" @printBoxCancel="printBoxCancel" ref="printBoxRef"></printBoxRidge>

    <!-- 按卷上架中的上架页面 -->
    <el-dialog title="档案上架" :visible.sync="jopen" width="55%" append-to-body>
      <div style="width: 97%; margin: 0 auto; padding-bottom: 1%">
      <el-form :model="upjParams" ref="upjForm"  :inline="true" label-width="68px">
        <el-form-item label="案卷号" prop="keyword">
          <el-input v-model="upjParams.keyword" placeholder="请输入案卷号" clearable style="width: 240px"
                    @keyup.enter.native="handleUpjQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search"  @click="handleUpjQuery">查询</el-button>
          <el-button icon="el-icon-refresh"  @click="resetUpjQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-top"  @click="submitUpJuan">确定上架并返回</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="upjLoading" :data="upjList" @selection-change="upjSelectionChange" @row-dblclick="openJuanDetails" height="450">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" type="index" :index="table_index_upj" prop="id" />
        <el-table-column label="案卷题名" prop="title" :show-overflow-tooltip="true" />
        <el-table-column label="案卷号" prop="ajh" :show-overflow-tooltip="true" />
        <el-table-column label="档号" prop="dh" :show-overflow-tooltip="true" />
        <el-table-column label="保管期限" prop="bgqx" :show-overflow-tooltip="true" />
        <el-table-column label="归档司局" prop="gdsj" :show-overflow-tooltip="true" />
        <el-table-column label="归档处室" prop="gdcs" :show-overflow-tooltip="true" />
<!--        <el-table-column label="上架时间" prop="sjTime" :show-overflow-tooltip="true" />-->
<!--        <el-table-column label="位置" prop="position" :show-overflow-tooltip="true" />-->
      </el-table>
      <pagination v-show="upjTotal > 0" :total="upjTotal" :page.sync="upjParams.pageNum"
                  :limit.sync="upjParams.pageSize" @pagination="getUpjList" />
      </div>
    </el-dialog>

    <!-- 按盒上架的上架页面 -->
    <el-dialog title="档案上架" :visible.sync="hopen" width="55%" append-to-body>
      <div style="width: 97%; margin: 0 auto; padding-bottom: 1%">
      <el-form :model="uphParams" ref="uphForm"  :inline="true" label-width="68px">
        <el-form-item label="盒号" prop="keyword">
          <el-input v-model="uphParams.keyword" placeholder="请输入盒号" clearable style="width: 240px"
                    @keyup.enter.native="handleUphQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search"  @click="handleUphQuery">查询</el-button>
          <el-button icon="el-icon-refresh"  @click="resetUphQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-top"  @click="submitUpHe">确定上架并返回</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="uphLoading" :data="uphList" @selection-change="uphSelectionChange" @row-dblclick="openHeDetails" height="450">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" type="index" :index="table_index_uph" prop="id" />
        <el-table-column label="盒号" prop="hehao" :show-overflow-tooltip="true" />
        <el-table-column label="档案门类" prop="daml" :show-overflow-tooltip="true" />
<!--        <el-table-column label="整理方式" prop="zlfs" :show-overflow-tooltip="true" />-->
        <el-table-column label="保管期限" prop="bgqx" :show-overflow-tooltip="true" />
        <el-table-column label="起始年度" prop="boxStnd" :show-overflow-tooltip="true" />
        <el-table-column label="终止年度" prop="boxEdnd" :show-overflow-tooltip="true" />
        <el-table-column label="件号(起)" prop="boxStnum" :show-overflow-tooltip="true" />
        <el-table-column label="件号(止)" prop="boxEdnum" :show-overflow-tooltip="true" />
        <el-table-column label="规格" prop="specName" :show-overflow-tooltip="true" />
<!--        <el-table-column label="上架时间" prop="sjTime" :show-overflow-tooltip="true" />-->
<!--        <el-table-column label="位置" prop="position" :show-overflow-tooltip="true" />-->
      </el-table>
      <pagination v-show="uphTotal > 0" :total="uphTotal" :page.sync="uphParams.pageNum"
                  :limit.sync="uphParams.pageSize" @pagination="getUphList" />
      </div>
    </el-dialog>

    <!-- 下架页面 -->
    <el-dialog title="档案下架" :visible.sync="downopen" width="35%" append-to-body>
      <el-form ref="downForm" :model="downForm" :rules="downRules" label-width="100px">
        <el-form-item label="下架原因" prop="xjyy">
          <el-input v-model="downForm.xjyy" type="textarea" placeholder="请输入内容" style="width: 90%" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="downForm.bz" type="textarea" placeholder="请输入内容" style="width: 90%" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="downShelf">确 定</el-button>
        <el-button @click="downopen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 调整档案位置弹窗 -->
    <el-dialog title="调整盒子所在位置" :visible.sync="adjustOpen" width="35%" append-to-body>
      <div style="overflow-y: auto; height: 250px">
        <el-tree ref="adjustTree" :data="treeData" @node-click="handleTreeNodeClick" node-key="id" :props="defaultProps" default-expand-all></el-tree>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAdjust">确 定</el-button>
        <el-button @click="adjustOpen = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 按卷上架列表页面双击 -->
    <upJuanDetail :upJuanOpen="upJuanOpen" @upJuanCancel="upJuanCancel" ref="upJuanRef"></upJuanDetail>

    <!-- 按盒上架列表页面双击 -->
    <upHeDetail :upHeOpen="upHeOpen" @upHeCancel="upHeCancel" ref="upHeRef"></upHeDetail>
  </div>
</template>

<script>
import {getTreeList} from "@/api/archive/warehouseManagement/warehouseInformation";
import {
  getcateidbyid,
  getDataList,
  getGridList,
  getPosition, getthbytreenodeHeaderList,
  grouding,
  offShelf, printRidgeBox, relocation
} from "@/api/archive/warehouseManagement/upDownShelves";
import estimateTableHeight from '@/mixins/estimateTableHeight'; //vue项目中element-tabel自动计算高度
import upJuanDetail from "@/views/archive/warehouseManagement/upDownShelves/upJuanDetail";
import upHeDetail from "@/views/archive/warehouseManagement/upDownShelves/upHeDetail";
import printBoxRidge from "@/views/archive/warehouseManagement/upDownShelves/printBoxRidge";
import {getLastIndexOf} from "@/utils";
import jianDetailsOpen from "@/components/componentsJianDetails";
import juanDetailsOpen from "@/components/componentsJuanDetails";
import {updateStatus} from "@/api/archive/warehouseManagement/technicalProcessing";
export default {
  name: "index",
  mixins: [estimateTableHeight], // 混入方法
  archive_Dicts: ['BGQX'],
  components: {
    upJuanDetail, upHeDetail, printBoxRidge
  },
  data() {
    const inputName = (rule, value, callback) => {
      if (value.trim() === '') {
        callback(new Error('输入不能为空格'));
      } else {
        callback();
      }
    }
    return {
      size: "",
      // 树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      //默认展开的树节点
      expandedkeys: [],
      //默认选中的树节点
      currentNodekey: "",
      parentKufangIdList: [],
      parentShelfIdList: [],
      shelfId: '',
      //上下架form
      upDownForm: {},
      //tabs标签切换默认选择项
      activeName: 'first',
      // 判断如果不是档案格就不显示右侧tabs的数据
      isfondsCode: "",
      juanParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined
      },
      showJuanSearch: true,
      juanLoading: false,
      // 按卷上架表格数据
      juanList: [],
      // 总条数
      juanTotal: 0,
      // 选中数据
      juanIds: [],
      juanids: [],
      // 出库状态
      juanOutBoundStatus: [],
      // 非单个禁用
      juanSingle: true,
      // 非多个禁用
      juanMultiple: true,
      // 是否打开详情页
      upJuanOpen: false,

      heParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined
      },
      showHeSearch: true,
      heLoading: false,
      // 按卷上架表格数据
      heList: [],
      // 总条数
      heTotal: 0,
      // 选中数据
      heIds: [],
      heids: [],
      // 非单个禁用
      heSingle: true,
      // 非多个禁用
      heMultiple: true,
      // 是否打开详情页
      upHeOpen: false,

      // 按卷上架弹窗
      // 弹窗是否显示
      jopen: false,
      upjParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined
      },
      upjTotal: 0,
      upjLoading: true,
      upjList: [],
      // 选中数据
      upjIds: [],
      upjids: [],
      // 非单个禁用
      upjSingle: true,
      // 非多个禁用
      upjMultiple: true,
      uploadJuan: true,

      // 打印盒脊弹窗
      printBoxOpen: false,

      // 按盒上架弹窗
      // 弹窗是否显示
      hopen: false,
      uphParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined
      },
      uphTotal: 0,
      uphLoading: true,
      uphList: [],
      // 选中数据
      uphIds: [],
      uphids: [],
      // 出库状态
      heOutBoundStatus: [],
      // 非单个禁用
      uphSingle: true,
      // 非多个禁用
      uphMultiple: true,
      uploadHe: true,

      // 下架弹窗
      downPage: "",
      downopen: false,
      downForm: {
        xjyy: undefined,
        bz: undefined
      },
      downRules: {
        xjyy: [
          { required: true, message: "下架原因不能为空", trigger: "blur" },
          { trigger: 'blur', validator: inputName }
        ]
      },

      // 调整档案位置弹窗
      adjustOpen: false,
      treeData: [],
      adjustPage: "",
      // 调整上下架form表单
      treeForm: {},
    }
  },
  created() {
    if (this.$store.getters.size == 'small') {
      this.size = 'font-size: 12px;'
    } else {
      this.size = 'font-size: 14px;'
    }
    this.getDeptTree()
  },
  methods: {
    getDeptTree(item) {
      if(item == undefined) {
        getTreeList().then(response => {
          this.deptOptions = response.data;
          this.treeData = response.data;
          this.isfondsCode = true
        })
      } else {
        getTreeList().then(response => {
          this.deptOptions = response.data;
          this.treeData = response.data;
          this.isfondsCode = true
          if (this.deptOptions.length > 0) {
            const data = this.findMatchingNode(this.deptOptions, this.shelfId)
            getGridList(this.shelfId).then(response => {
              const children = response.rows.map(item =>{
                return {
                  id: item.gridId,
                  label: item.gridName+ " 已上架" +item.putawayNum,
                  nodeType: "grid"
                }
              }); // 子节点数据
              data.children = children; // 将子节点数据追加到当前节点的children属性中
              console.log(data)
              // 直接修改this.deptOptions中的对应数据
              this.deptOptions.forEach(node => {
                if(node.id === this.shelfId) {
                  node = data;
                }
              });
              this.deptOptions = [...this.deptOptions]; // 重新赋值，触发更新
              this.treeData = [...this.treeData]
              this.currentNodeKey = this.upDownForm.id;
              this.expandedkeys.push(this.upDownForm.id);
              this.$nextTick(() => {
                this.$refs.tree.setCurrentKey(this.upDownForm.id)
              })
              const code = this.findMatchingNode(this.deptOptions, this.upDownForm.id)
              // id
              this.upDownForm.id = code.id
              // 节点类型
              this.upDownForm.nodeType = code.nodeType
              this.isfondsCode = code.nodeType == "grid" ? false : true;
              if(this.upDownForm.nodeType == "grid") {
                this.getJuanList()
                this.getHeList()
              }
            })
          }
        })
      }
    },
    findMatchingNode(tree, id) {
      for (const node of tree) {
        if (node.id === id) {
          return node; // 匹配到的节点
        }
        if (node.children && node.children.length > 0) {
          const match = this.findMatchingNode(node.children, id);
          if (match !== null) {
            return match;
          }
        }
      }
      return null; // 如果没有找到匹配的节点，返回null
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data,node) {
      console.log(data)
      this.juanParams.pageSize = 10
      this.juanParams.pageNum = 1
      this.heParams.pageNum = 1
      this.heParams.pageSize = 10
      // console.log(node)
      // id
      this.upDownForm.id = data.id
      if(data.nodeType == "region") {
        const id = data.id.split("_")
        this.upDownForm.id= id[0]
      } else {
        this.upDownForm.id = data.id
      }
      // 节点类型
      this.upDownForm.nodeType = data.nodeType
      // 库房id
      this.parentKufangIdList = []
      // 档案柜id
      this.parentShelfIdList = []
      this.getParent(node)
      this.upDownForm.kufangId = this.parentKufangIdList[0]
      this.shelfId = this.parentShelfIdList[0]
      console.log(this.shelfId)

      this.isfondsCode = data.nodeType == "grid" ? false : true;

      if(this.upDownForm.nodeType == "shelf") {
        getGridList(this.upDownForm.id).then(response => {
          const children = response.rows.map(item =>{
            return {
              id: item.gridId,
              label: item.gridName+ " 已上架" +item.putawayNum,
              nodeType: "grid"
            }
          }); // 子节点数据
          data.children = children; // 将子节点数据追加到当前节点的children属性中
          this.deptOptions = [...this.deptOptions]; // 重新赋值，触发更新
          this.treeData = [...this.treeData]
        })
      }

      if(this.upDownForm.nodeType == "grid") {
        this.getJuanList()
        this.getHeList()
      }
    },
    // 判断获取库房id
    getParent(node) {
      // 判断当前节点是否有父节点，并且父节点上的data不能是数组
      if (node.parent && !Array.isArray(node.parent.data)) {
        if (node.parent.data.id != null && node.parent.data.nodeType == "store") {
          // 将父节点上data的menuid存储在 `parentlist` 里
          node.parent.data instanceof Object && this.parentKufangIdList.push(node.parent.data.id)
        }
        if (node.parent.data.id != null && node.parent.data.nodeType == "shelf") {
          // 将父节点上data的menuid存储在 `parentlist` 里
          node.parent.data instanceof Object && this.parentShelfIdList.push(node.parent.data.id)
        }
        // 递归调用 父节点上有父节点
        this.getParent(node.parent)
        // 当父节点上data是数组时点击对象为当前tree最高目录 并且parentList必须是0
      }
    },


    // 按卷上架 搜索按钮操作
    handleJuanQuery() {
      this.juanParams.pageNum = 1;
      this.getJuanList()
    },
    // 按卷上架 重置按钮操作
    resetJuanQuery() {
      this.resetForm("juanForm");
      this.getJuanList()
    },
    juanSelectionChange(selection) {
      this.juanIds = selection.map(item => item.id)
      this.juanboxIds = selection.map(item => item.boxId)
      this.juanids = selection.map(item => item.id+";"+item.subTableName)
      this.juanDataList = selection.map(item => {
        return {
          daId: item.id,
          tableName: item.subTableName,
          kfId: this.upDownForm.kufangId
        }
      })
      this.juanOutBoundStatus = selection.map(item => item.outBoundStatus)
      this.juanSingle = selection.length != 1
      this.juanMultiple = !selection.length
    },
    table_index_juan(index) {
      return (this.juanParams.pageNum - 1) * this.juanParams.pageSize + index + 1;
    },
    getJuanList() {
      this.juanLoading = true
      this.juanParams.gridId = this.upDownForm.id
      this.juanParams.sjType = '1'
      this.juanParams.type = '1'
      getDataList(this.juanParams).then(response => {
        this.juanList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          // 渲染表格数据
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].bgqx == this.dict.type.BGQX[j].value){
              this.juanList[i].bgqx = this.dict.type.BGQX[j].label
            }
          }
        }
        this.juanTotal = response.total
        this.juanLoading = false
      })
    },
    // 按卷上架---上架按钮
    upJuan() {
      this.jopen = true
      this.getUpjList()
    },
    // 按卷上架---下架按钮
    downJuan(row) {
      const ids = row.id || this.juanIds
      this.resetForm('downForm')
      if(ids.length == 0) {
        this.$modal.msgWarning("请选择至少一条记录");
      } else {
        const outBoundStatus = this.juanOutBoundStatus
        if(outBoundStatus.includes(1)) {
          this.$modal.msgWarning("上架位置中包含已出库的文件,不能下架");
        } else {
          this.resetDownForm()
          this.downopen = true
          this.downPage = "downJuan"
        }
      }
    },
    // 按卷上架---调整档案位置
    adjustJuan(row) {
      const ids = row.id || this.juanIds
      if(ids.length == 0) {
        this.$modal.msgWarning("请选择至少一条记录");
      } else {
        // const outBoundStatus = this.juanOutBoundStatus
        // if(outBoundStatus.includes("1")) {
        //   this.$modal.msgWarning("文件中包含已出库的文件,不能调整位置");
        // } else {
        this.adjustOpen = true
        this.adjustPage = "adjustJuan"
        // }
      }
    },
    // 双击行数据出现新页面
    openJuanDetails(row) {
      console.log("双击了")
      const id = row.id
      this.upJuanOpen = true
      this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
        this.$refs.upJuanRef.init(id);     //获取子组件中init方法并将父组件数据传递给子组件
      });
    },
    upJuanCancel() {
      this.upJuanOpen = false
    },
    // 按卷上架的上架弹窗
    handleUpjQuery() {
      this.upjParams.pageNum = 1;
      this.getUpjList()
    },
    resetUpjQuery() {
      this.resetForm("upjForm");
      this.getUpjList()
    },
    // 确定上架并返回按钮
    submitUpJuan(row) {
      if (this.uploadJuan) {
        this.uploadJuan = false
        const ids = row.id || this.upjids
        if(ids.length==0){
          this.$modal.msgWarning('请选择数据！')
          return false;
        }
        // 通过格子id获取位置
        getPosition(this.upDownForm.id).then(response => {
          const position = response.msg
          this.form = {
            type: '1',
            gzId: this.upDownForm.id,
            kfId: this.upDownForm.kufangId,
            ids: ids.toString(),
            position: position
          }
          console.log(this.form)
          grouding(this.form).then(response=>{
            this.$modal.msgSuccess("上架成功");
            this.jopen = false
            // this.getJuanList()
            this.getDeptTree('item')
            setTimeout(() => {
              this.uploadJuan = true
            }, 300)
          }).catch(() => {
            setTimeout(() => {
              this.uploadJuan = true
            }, 300)
          })
        })
      }
    },
    upjSelectionChange(selection) {
      this.upjIds = selection.map(item => item.id)
      this.upjids = selection.map(item => item.id+";"+item.subTableName)
      this.upjSingle = selection.length != 1
      this.upjMultiple = !selection.length
    },
    table_index_upj(index) {
      return (this.upjParams.pageNum - 1) * this.upjParams.pageSize + index + 1;
    },
    getUpjList() {
      this.upjLoading = true
      this.upjParams.gridId = this.upDownForm.id
      this.upjParams.sjType = '1'
      this.upjParams.type = '0'
      getDataList(this.upjParams).then(response => {
        this.upjList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          // 渲染表格数据
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].bgqx == this.dict.type.BGQX[j].value){
              this.upjList[i].bgqx = this.dict.type.BGQX[j].label
            }
          }
        }
        this.upjTotal = response.total
        this.upjLoading = false
      })
    },



    // 确定下架
    downShelf() {
      var id = ""
      if(this.downPage == "downJuan") {
        id = this.juanids
        this.downForm.type = '1'
      } else if(this.downPage == "downHe") {
        id = this.heids
        this.downForm.type = '0'
      }
      this.downForm.gzId = this.upDownForm.id
      this.downForm.kfId = this.upDownForm.kufangId
      this.downForm.ids = id.toString()
      console.log(this.downForm)
      this.$refs["downForm"].validate(valid => {
        if(valid) {
          offShelf(this.downForm).then(response=>{
            this.$modal.msgSuccess("下架成功");
            this.downopen = false
            this.downPage = ""
            this.juanids = []
            this.juanIds = []
            this.heids = []
            this.heIds = []
            // this.getJuanList()
            // this.getHeList()
            this.getDeptTree('item')
          })
        }
      })
    },
    resetDownForm() {
      this.downForm = {
        xjyy: undefined,
        bz: undefined
      }
    },

    handleTreeNodeClick(data) {
      console.log(data)
      // this.treeForm.id = data.id
      if(data.nodeType == "region") {
        const id = data.id.split("_")
        this.treeForm.id = id[0]
      } else {
        this.treeForm.id = data.id
      }
      this.treeForm.nodeType = data.nodeType
    },
    // 确定调整位置
    submitAdjust() {
      if(this.treeForm.nodeType != 'grid'){
        this.$modal.msgWarning("请先选择上架的位置!")
      } else {
        var id = ""
        var type = ""
        if(this.adjustPage == "adjustJuan") {
          id = this.juanids
          type = '1'
        } else if(this.adjustPage == "adjustHe") {
          id = this.heids
          type = '0'
        }
        getPosition(this.treeForm.id).then(response=>{
          const position = response.msg
          this.form = {
            type: type,
            gzId: this.upDownForm.id,
            newGzId: this.treeForm.id,
            ids: id.toString(),
            newPosition: position
          }
          console.log(this.form)
          relocation(this.form).then(response=>{
            this.$modal.msgSuccess("调整位置成功");
            this.adjustOpen = false
            this.adjustPage = ""
            this.juanids = []
            this.juanIds = []
            this.heids = []
            this.heIds = []
            // this.getJuanList()
            // this.getHeList()
            this.getDeptTree('item')
          })
        })
      }
    },


    // 按盒上架 搜索按钮操作
    handleHeQuery() {
      this.heParams.pageNum = 1;
      this.getHeList()
    },
    // 按卷上架 重置按钮操作
    resetHeQuery() {
      this.resetForm("heForm");
      this.getHeList()
    },
    heSelectionChange(selection) {
      this.heIds = selection.map(item => item.id)
      this.heboxIds = selection.map(item => item.boxId)
      this.heids = selection.map(item => item.id+";"+item.subTableName)
      this.heDataList = selection.map(item => {
        return {
          daId: item.id,
          tableName: item.subTableName,
          kfId: this.upDownForm.kufangId
        }
      })
      this.heOutBoundStatus = selection.map(item => item.outBoundStatus)
      this.heSingle = selection.length != 1
      this.heMultiple = !selection.length
    },
    table_index_he(index) {
      return (this.heParams.pageNum - 1) * this.heParams.pageSize + index + 1;
    },
    getHeList() {
      this.heLoading = true
      this.heParams.gridId = this.upDownForm.id
      this.heParams.sjType = '0'
      this.heParams.type = '1'
      getDataList(this.heParams).then(response => {
        this.heList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          // 渲染表格数据
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].bgqx == this.dict.type.BGQX[j].value){
              this.heList[i].bgqx = this.dict.type.BGQX[j].label
            }
          }
          if(response.rows[i].specDw == '0'){
            this.heList[i].specName = response.rows[i].specName + 'mm'
          } else {
            this.heList[i].specName = response.rows[i].specName + 'cm'
          }
        }
        this.heTotal = response.total
        this.heLoading = false
      })
    },
    // 按盒上架---打印盒脊
    printHe(row) {
      const ids = row.id || this.heIds;
      if(ids.length == 0) {
        this.$modal.msgError("请选择要打印的数据");
      } else {
        this.form = {
          ids: ids.toString()
        }
        printRidgeBox(this.form).then(response => {
          var list = response.data
          for (let i = 0; i < response.data.length; i++) {
            for (let j = 0; j < this.dict.type.BGQX.length; j++) {
              if(response.data[i].boxBgqx == this.dict.type.BGQX[j].value){
                response.data[i].boxBgqx = this.dict.type.BGQX[j].label
              }
            }
          }
          let data = response.data.map(item =>{
            return{
              qzh: item.boxQzh,
              stnd: item.boxStnd,
              ednd: item.boxEdnd,
              bgqx: item.boxBgqx,
              stnum: item.boxStnum,
              ednum: item.boxEdnum,
              hehao: item.hehao
            }
          })
          console.log(data)
          this.printBoxOpen = true
          this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
            this.$refs.printBoxRef.init(data);     //获取子组件中init方法并将父组件数据传递给子组件
          });
        })
      }
    },
    printBoxCancel() {
      this.printBoxOpen = false
    },
    // 按盒上架---上架按钮
    upHe() {
      this.hopen = true
      this.getUphList()
    },
    // 按盒上架---下架按钮
    downHe(row) {
      this.resetForm('downForm')
      const ids = row.id || this.heIds
      if(ids.length == 0) {
        this.$modal.msgWarning("请选择至少一条记录");
      } else {
        const outBoundStatus = this.heOutBoundStatus
        if (outBoundStatus.includes(1)) {
          this.$modal.msgWarning("上架位置中包含已出库的文件,不能下架");
        } else {
          this.resetDownForm()
          this.downopen = true
          this.downPage = "downHe"
        }
      }
    },
    // 按盒上架---调整档案位置
    adjustHe(row) {
      const ids = row.id || this.heIds
      if(ids.length == 0) {
        this.$modal.msgWarning("请选择至少一条记录");
      } else {
        // const outBoundStatus = this.heOutBoundStatus
        // if(outBoundStatus.includes("1")) {
        //   this.$modal.msgWarning("文件中包含已出库的文件,不能调整位置");
        // } else {
        this.adjustOpen = true
        this.adjustPage = "adjustHe"
        // }
      }
    },
    // 双击行数据出现新页面
    openHeDetails(row) {
      console.log("双击了",row)
      const id = row.id
      this.upHeOpen = true
      this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
        this.$refs.upHeRef.init(id);     //获取子组件中init方法并将父组件数据传递给子组件
      });
    },
    upHeCancel() {
      this.upHeOpen = false
    },
    // 按卷上架的上架弹窗
    handleUphQuery() {
      this.uphParams.pageNum = 1;
      this.getUphList()
    },
    resetUphQuery() {
      this.resetForm("uphForm");
      this.getUphList()
    },
    // 确定上架并返回按钮
    submitUpHe(row) {
      if (this.uploadHe) {
        this.uploadHe = false
        const ids = row.id || this.uphids
        if (ids.length==0){
          this.$modal.msgWarning('请选择数据！')
          return false;
        }
        // 通过格子id获取位置
        getPosition(this.upDownForm.id).then(response => {
          const position = response.msg
          this.form = {
            type: '0',
            gzId: this.upDownForm.id,
            kfId: this.upDownForm.kufangId,
            ids: ids.toString(),
            position: position
          }
          console.log(this.form)
          grouding(this.form).then(response=>{
            this.$modal.msgSuccess("上架成功");
            this.hopen = false
            // this.getHeList()
            this.getDeptTree('item')
            setTimeout(() => {
              this.uploadHe = true
            }, 300)
          }).catch(() => {
            setTimeout(() => {
              this.uploadHe = true
            }, 300)
          })
        })
      }
    },
    uphSelectionChange(selection) {
      this.uphIds = selection.map(item => item.id)
      this.uphids = selection.map(item => item.id+";"+item.subTableName)
      this.uphSingle = selection.length != 1
      this.uphMultiple = !selection.length
    },
    table_index_uph(index) {
      return (this.uphParams.pageNum - 1) * this.uphParams.pageSize + index + 1;
    },
    getUphList() {
      this.uphLoading = true
      this.uphParams.gridId = this.upDownForm.id
      this.uphParams.sjType = '0'
      this.uphParams.type = '0'
      getDataList(this.uphParams).then(response => {
        this.uphList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          // 渲染表格数据
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].bgqx == this.dict.type.BGQX[j].value){
              this.uphList[i].bgqx = this.dict.type.BGQX[j].label
            }
          }
        }
        this.uphTotal = response.total
        this.uphLoading = false
      })
    },

    // 数字化/微缩/修复/保护技术处理
    modifyState(val) {
      var form = {
        status: val,
        type: '0'
      }
      if (this.activeName == 'first') {
        form.ids = this.juanboxIds
        form.List = this.juanDataList
      } else {
        form.ids = this.heboxIds
        form.List = this.heDataList
      }
      if (form.ids.length == 0||form.ids==undefined) {
        this.$modal.msgWarning('请选择至少一条数据')
        return
      }
      updateStatus(form).then(res=>{
        this.$modal.msgSuccess('添加成功')
        this.getJuanList()
        this.getHeList()
        this.getDeptTree('item')
        setTimeout(() => {
          this.uploadJuan = true
        }, 300)
      })
    }
  },
}
</script>

<style lang="scss" scoped>
//::v-deep .el-dialog {
//  display: flex;
//  flex-direction: column;
//  margin: 0 !important;
//  position: absolute;
//  top: 50%;
//  left: 50%;
//  transform: translate(-50%, -50%);
//  max-height: calc(100% - 30px);
//  max-width: calc(100% - 30px);
//}
//
//::v-deep .el-dialog .el-dialog__body {
//  flex: 1;
//  overflow: auto;
//}
</style>
